<?php

namespace app\admin\controller;

use think\Controller;
use think\Db;
use think\facade\Request;

class Test extends Controller
{
    public function index(){
        return $this->fetch();
    }
    public function test(){
        //$count 总页数
        $size=10;
        $count=db('products')->count();
        $count=ceil($count/$size);

        //第几页
        $now=Request::param();
        //页数存在获取值否则为1
        $now=$now['now']??1;
        //当前页小于1则为1；
        $now=$now<1?1:$now;
        //当前页大于最大页数就是最大页数否则就是本身;
        $now=$now>$count?$count:$now;
        $lim=($now-1)*$size;
        $data=Db::table('products')->limit($lim,$size)->select();
        return $this->fetch('test',['data'=>$data,'count'=>$count,'now'=>$now]);
    }
    //查
    public function select(){
        $pro=Request::param('pro');
        $data=Db::table('products')->where('proname',$pro)->select();
        return $this->fetch('select',['data'=>$data]);
    }
    //删
    public function del(){
        $id=Request::param('id');
        Db::table('products')->where('proID',$id)->delete();

        //$count 总页数
        $size=10;
        $count=db('products')->count();
        $count=ceil($count/$size);

        //第几页
        $now=Request::param();
        //页数存在获取值否则为1
        $now=$now['now']??1;
        //当前页小于1则为1；
        $now=$now<1?1:$now;
        //当前页大于最大页数就是最大页数否则就是本身;
        $now=$now>$count?$count:$now;
        $lim=($now-1)*$size;
        $data=Db::table('products')->limit($lim,$size)->select();
        return $this->fetch('test',['data'=>$data,'count'=>$count,'now'=>$now]);
    }

    //添加
    public function add(){
        return $this->fetch();
    }

    public function addd(){
        $data=Request::param();
        $proname=$data['proname'];
        $proprice=$data['proprice'];
        $proguige=$data['proguige'];
        $data=['proname'=>$proname,'proguige'=>$proguige,'proprice'=>$proprice,'pro','proamount'=>$proprice,'proimages'=>'images\15.bmp','proweb'=>' $proname=$data[$proname];
        '];
        Db::name('products')->strict(false)->insert($data);
        

         //$count 总页数
         $size=10;
         $count=db('products')->count();
         $count=ceil($count/$size);
 
         //第几页
         $now=Request::param();
         //页数存在获取值否则为1
         $now=$now['now']??1;
         //当前页小于1则为1；
         $now=$now<1?1:$now;
         //当前页大于最大页数就是最大页数否则就是本身;
         $now=$now>$count?$count:$now;
         $lim=($now-1)*$size;
         $data=Db::table('products')->limit($lim,$size)->select();
         return $this->fetch('test',['data'=>$data,'count'=>$count,'now'=>$now]);
        
    }

    public function edit(){
        $data=Request::param('id');
        $data=Db::table('products')->where('proID',$data)->select();
        return $this->fetch('edit',['data'=>$data]);
    }

    public function editt(){
        $data=Request::param();
        $proID=$data['proID'];
        $proname=$data['proname'];
        $proprice=$data['proprice'];
        $proguige=$data['proguige'];
        Db::name('products')->where('proID',$proID)->data(['proname' =>$proname,'proprice'=>$proprice,'proguige'=>$proguige])->update();

        //$count 总页数
        $size=10;
        $count=db('products')->count();
        $count=ceil($count/$size);

        //第几页
        $now=Request::param();
        //页数存在获取值否则为1
        $now=$now['now']??1;
        //当前页小于1则为1；
        $now=$now<1?1:$now;
        //当前页大于最大页数就是最大页数否则就是本身;
        $now=$now>$count?$count:$now;
        $lim=($now-1)*$size;
        $data=Db::table('products')->limit($lim,$size)->select();
        return $this->fetch('test',['data'=>$data,'count'=>$count,'now'=>$now]);
    }
}
